'use strict';

import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
  indexAction(){
    //auto render template file index_index.html
    return this.display();
  }
  
	async getadmininfoAction(){
    let shopid = this.shop_userinfo.departmentid;

    let adminid = this.shop_userinfo.id;

		let ainfo = await this.model('or_admin').where({id: adminid}).find();

    let initConfig = await this.model('or_shop_basis').where({shopid: shopid}).find();

    let data = {
      ainfo: ainfo,
      initConfig: initConfig
    }

		return this.json(data);
	}

  async getbroadcastAction(){
    let uinfo = await this.model('or_admin').where({id:this.shop_userinfo.id}).find();
    let depar = await this.model('or_department').where({id: uinfo.departmentid}).find();
    if (depar.floor <= 1) {
      let gb = await this.model('or_broadcast').where({range:depar.floor}).find();
      return this.json(gb);
    } else {
      return this.json({
        isbroadcast : 2
      });
    }
    
  }
}